/**
 * 
 */
package sourceFiles;

import java.util.TreeMap;

/**
 * A class representing the E-Tickets every child registered to the park has to
 * it's name. contains listing for regular as well as extreme ride tickets
 * 
 * @author LASO-Team
 * 
 */
public class ETicket {

	private TreeMap<Integer, Integer> extremeRidesTickets;
	private Integer regualrRidesTickets = 0;

	/*--------------------------------------------------------------------------*/

	/**
	 * A simple constructor for the E-Ticket using a tree map for listing the
	 * number of tickets for every extreme ide the child has.
	 */
	public ETicket() {
		super();
		this.extremeRidesTickets = new TreeMap<Integer, Integer>();
	}

	/**
	 * Getter for the container holding all the extreme ride tickets in the
	 * E-TIcket
	 * 
	 * @return the mapping between the ride's ID to the number of tickets.
	 */
	public TreeMap<Integer, Integer> getExtremeRidesList() {
		return extremeRidesTickets;
	}

	/**
	 * Getter for the number of regular tickets the child holds.
	 * 
	 * @return the number of regular tickets the child holds.
	 */
	public Integer getRegualrRidesTickets() {
		return regualrRidesTickets;
	}

	/**
	 * adds a single ticket to the regular rides tickets.
	 */
	public void addRegularTicket() {
		this.regualrRidesTickets++;
	}

	/**
	 * removes a single ticket to the regular rides tickets.
	 */
	public void removeRegularTicket() {
		if (this.regualrRidesTickets > 0) {
			this.regualrRidesTickets--;
		}
	}

	/**
	 * adds a single ticket to the specified extreme ride tickets.
	 * 
	 * @param rideID
	 *            the ride that we add an extreme ticket to.
	 */
	public void addExtremeTicket(Integer rideID) {
		int tickets = 0;
		if (this.extremeRidesTickets.containsKey(rideID)) {
			tickets = this.extremeRidesTickets.get(rideID);
		}
		this.extremeRidesTickets.put(rideID, tickets + 1);
	}

	/**
	 * removes a single ticket to the specified extreme ride tickets.
	 * 
	 * @param rideID
	 *            the ride that we remove it's ticket.
	 */
	public void removeExtremeTicket(Integer rideID) {
		if (!this.extremeRidesTickets.containsKey(rideID)) {
			return;
		}
		if (this.extremeRidesTickets.get(rideID) == 1) {
			this.extremeRidesTickets.remove(rideID);
			return;
		}
		int tickets = this.extremeRidesTickets.get(rideID);
		this.extremeRidesTickets.put(rideID, tickets - 1);
	}

	/**
	 * finds if there is a ticket existing in the child's E-Ticket for the
	 * specified ride (ignors ride id if ride is regular)
	 * 
	 * @param rideID
	 *            the identifier if the ride is extreme.
	 * @param isExtreme
	 *            a boolean value that specifies whether the ride is extreme or
	 *            not.
	 * @return if there is a ticket to the ride with the ID rideID
	 */
	public Boolean ticketExists(Integer rideID, Boolean isExtreme) {
		if (isExtreme) {
			return this.extremeRidesTickets.containsKey(rideID);
		}
		return this.regualrRidesTickets > 0;
	}
}
